package cn.com.pc.content.controller;

import cn.com.pc.content.annotation.LogRequired;
import cn.com.pc.content.service.RebuildEsContentIndexService;
import cn.com.pc.content.service.RebuildEsTagIndexService;
import cn.com.pc.rbac.client.annotation.NeedRole;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Properties;

import static cn.com.pc.content.constant.RbacConstants.ADMIN;


/**
 * 快速重建ES索引数据
 */
@RestController
@RequestMapping("/es-index")
public class EsIndexController {

    @Autowired
    private RebuildEsTagIndexService rebuildEsTagIndexService;

    @Autowired
    private RebuildEsContentIndexService rebuildEsContentIndexService;

    @PostMapping("/tags/rebuild")
    @NeedRole(ADMIN)
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @LogRequired(operation = "同步pcp_tags索引数据")
    public void rebuildTags() {
        rebuildEsTagIndexService.rebuild();
    }

    @PostMapping("/content/rebuild")
    @NeedRole(ADMIN)
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @LogRequired(operation = "'同步' + #indexName + '索引数据'")
    public void rebuildContent(@RequestBody String indexName) {
        rebuildEsContentIndexService.rebuild(indexName);
    }
}
